package com.cltech.mapper;

import com.cltech.dto.SysOrganizationDto;
import com.cltech.dto.TreeNode;
import com.cltech.entity.sys.SysOrganization;
import org.mapstruct.*;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * Created by Administrator on 2019/4/9.
 */
@Mapper(componentModel = "spring")
public interface SysOrganizationMapper {
    @Mappings({
            @Mapping(source = "parentId", target = "parent.id"),
            @Mapping(source = "parentName", target = "parent.name"),
            @Mapping(source = "parentCode", target = "parent.code")
    })
    SysOrganization dtoToEntity(SysOrganizationDto sysOrganizationDto);
    @InheritConfiguration(name ="dtoToEntity")
    List<SysOrganization> dtoToEntity(List<SysOrganizationDto> sysOrganizationDto);
    @InheritInverseConfiguration(name ="dtoToEntity")
    SysOrganizationDto entityToDto(SysOrganization sysOrganization);
    @InheritInverseConfiguration(name ="dtoToEntity")
    List<SysOrganizationDto> entityToDto(List<SysOrganization> list);
    default Page<SysOrganizationDto>entityToDto(Page<SysOrganization> page){
        return page.map(this::entityToDto);
    }

    @Mappings({
            @Mapping(source = "id", target = "key"),
            @Mapping(source = "parent.id", target = "pid"),
            @Mapping(source = "name", target = "title"),
            @Mapping(source = "code", target = "code"),
            @Mapping(source = "children",target = "children",ignore = true)
    })
    TreeNode entityToTreeNode(SysOrganization sysOrganization);
    @InheritConfiguration(name ="entityToTreeNode")
    List<TreeNode>entityToTreeNode(List<SysOrganization> sysOrganization);
}